package net.oschina.app.ui;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import net.oschina.app.R;
import net.oschina.app.adapter.EventsPagerAdapter;
import net.oschina.app.viewpagerfragment.eventsdetailfragment.MyEventsFragment;
import net.oschina.app.viewpagerfragment.eventsdetailfragment.RecentEventsFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by huang on 2017-4-1.
 * 活动页面
 */

public class EventsActivity extends AppCompatActivity {

    @BindView(R.id.tb_events)
    Toolbar mTbEvents;
    @BindView(R.id.tl_events)
    TabLayout mTlEvents;
    @BindView(R.id.vp_events)
    ViewPager mVpEvents;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();
        initEvent();

    }

    @NonNull
    private void initView() {
        setContentView(R.layout.activity_events);
        ButterKnife.bind(this);//黄油刀绑定控件
        setSupportActionBar(mTbEvents);
        mTbEvents.setNavigationIcon(R.drawable.actionbar_back_icon_normal);

        mTlEvents.setupWithViewPager(mVpEvents);//TabLayout关联ViewPager

    }

    //初始化数据
    private void initData() {
        List<Fragment> datas = new ArrayList<>();
        datas.add(new RecentEventsFragment());
        datas.add(new MyEventsFragment());
        //ViewPager绑定Fragment
        mVpEvents.setAdapter(new EventsPagerAdapter(getSupportFragmentManager(),datas));

    }

    private void initEvent() {
        //监听toolBar导航图标(返回图标)
        mTbEvents.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //销毁本activity
                finish();
            }
        });
    }


}
